/*!
 * \file t_http_url_decode.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2016/03/31
 *
 */
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"

#include "../../../../src/module/http/config.h"
#include <http/comm/http_comm.h>
#include <http/http_core.h>
#include <frct_comm.h>
#include "frreport_comm.h"
#include "../../../comm/apmtest_comm.h"

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

static void __case1(void)
{
    char *p_src = NULL;
    char *p_dest = NULL;
    int i_ret = 0;

    i_ret = http_url_decode(p_src, 0, &p_dest);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);

    return;
}

static void __case2(void)
{
    char *p_src = frstrdup((const char *)"www.baidu.com&params%5B0%5D%5Bname%5D=name&params%5B0%5D%5Bvalue%5D=zxd&params%5B0%5D%5Bmethod%5D=get%5B0%5D");
    char *p_dest = NULL;
    int i_ret = 0;

    i_ret = http_url_decode(p_src, strlen(p_src), &p_dest);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    CU_ASSERT_STRING_EQUAL(p_dest, "www.baidu.com&params[0][name]=name&params[0][value]=zxd&params[0][method]=get[0]");

    frfree(p_src);
    frfree(p_dest);

    return;
}

int add_suite_http_url_decode(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" http_url_decode()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);

    return FR_SUCC;
}
